package filter.servletcontext;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Servlet_Demo3 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setContentType("text/html");
//        resp.setCharacterEncoding("gbk");
        //获取静态配置路径
        InputStream is = this.getServletContext().getResourceAsStream("/WEB-INF/classes/db.prope");
        //创建Properties对象，读取配置内容
        Properties peope=new Properties();
        peope.load(is);
        String uname = peope.getProperty("uname");
        String upwd = peope.getProperty("upwd");
        //进行网页上输出
        resp.getWriter().print(uname+":"+upwd);
        is.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
